<?php
if(!defined('INEZCMS')){
	exit('Access Denied');
}
$data["status"]=0;
$tid=intval($_GET["tid"]);

if(empty($userlogininfo)){
   $data["msg"]="请登录后，再发表评论!"; 
   echo json_encode($data);
   exit;    
}
if(empty($tid)){
    
   $data["msg"]="请选择文章!"; 
   echo json_encode($data);
   exit;    
    
}
if($_POST["valcode"]==""){
   $data["msg"]="验证码错误!"; 
   echo json_encode($data);
   exit;    
    
}
if($_POST["valcode"]!=$_SESSION["captcha"]){
   $_SESSION["captcha"]=""; 
   unset($_SESSION["captcha"]);
   $data["msg"]="验证码错误!"; 
   echo json_encode($data);
   exit;   
}
$_SESSION["captcha"]="";
if(trim($_POST["content"])==""){
    
  $data["msg"]="评论内容不能为空!"; 
   echo json_encode($data);
   exit;     
}
$cdata["tid"]=$tid;
$cdata["userid"]=$userlogininfo["uid"];
$cdata["username"]=$userlogininfo["ezusername"];
$cdata["creat_at"]=time();
$cdata["ip"]=get_client_ip();
$cdata["content"]=htmlspecialchars(trim($_POST["content"]));
$qid = $ezhand->insert('comment_data', $cdata, 0); 
if($qid>0){
    $data["status"]=1;
    $place=getIpPlace($cdata["ip"]);
    $ip=$cdata["ip"];
    $data["msg"]='<table width="750">
<tr><td class="commentstitle"><b>'.$cdata["username"].'</b> 于 <span class="comment_info">'.date("Y-m-d H:i:s").'</font>   ('.showIp($ip).' '.$place.')</span></td></tr>
<tr><td class="commentcontent">'.nl2br($cdata["content"]).'</td></tr>
</table>';

 $data2=array('f'=>'comments','e'=>'+','v'=>1);
 $ezhand->update('thread',$data2,'id="'.$tid.'"');      
       
}else{
  $data["status"]=0;
  $data["msg"]="系统错误，请联系管理员!"; 
}

echo json_encode($data);


?>